/*
 * Copyright (c) 2006, 2023, webrx.cn All rights reserved.
 *
 */
package cn.reg;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>Project: jse2302 - RegExp4
 * <p>Powered by webrx On 2023-06-20 14:35:24
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class RegExp4 {
    public static void main(String[] args) {
        //java.util.regex.Matcher  Pattern
        Pattern pattern = Pattern.compile("-?\\d+");
        String str = "0java16my-22php999";
        //0 16 22 999
        Matcher matcher = pattern.matcher(str);
        //匹配
        //System.out.println(matcher.matches());
        //System.out.println(str.matches(pattern.pattern()));

        StringBuilder sbu = new StringBuilder();
        int sum = 0;
        while (matcher.find()) {
            String g = matcher.group();
            System.out.println(g);
            sbu.append(String.format("%s + ", g));
            sum += Integer.parseInt(g);
        }
        System.out.println();
        System.out.printf("%s = %d", sbu.delete(sbu.length() - 2, sbu.length()), sum);
    }
}
